// https://leetcode.cn/problems/majority-element-ii/
// Created by ade on 2022/9/8.
// 给定一个大小为 n 的整数数组，找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<int> majorityElement(vector<int> &nums) {
        int len = nums.size();
        unordered_map<int, int> m = {};
        vector<int> res = {};
        for (auto i:nums) {
            m[i]++;
        }
        for (auto i : m) {
            if (i.second > len / 3) res.push_back(i.first);
        }
        return res;
    }
};

int main() {
    Solution so;
    vector<int> res = {1, 2};
    auto r = so.majorityElement(res);
    for (auto i : r) {
        cout << i << ",";
    }
    cout << endl;
    return 0;
}